/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   binNode_succ.h                                     :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: TYTY000 <767280080@qq.com>                 +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2024/04/23 14:16:12 by TYTY000           #+#    #+#             */
/*   Updated: 2024/04/23 14:16:12 by TYTY000          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef __BINNODE_SUCC__
#define __BINNODE_SUCC__

template <typename T> BinNodePosi<T> BinNode<T>::prev() {
  BinNodePosi<T> t = this;
  if (lc) {
    t = lc;
    while (HasRChild(*t))
      t = t->rc;
  } else {
    while (IsLChild(*t)) {
      t = t->parent;
    }
    t = t->parent;
  }
  return t;
}

template <typename T> BinNodePosi<T> BinNode<T>::succ() {
  BinNodePosi<T> t = this;
  if (rc) {
    t = rc;
    while (HasLChild(*t))
      t = t->lc;
  } else {
    while (IsRChild(*t))
      t = t->parent;
    t = t->parent;
  }
  return t;
}

#endif // !__BINNODE_SUCC__
